var e = require;
var t = module;
var o = exports;
var n;
Object.defineProperty(o, "__esModule", {value: !0});
var r = e("NavtiveData"),
    s = e("SDK"),
    c = e("NativeAdComponent"),
    l = e("Banner"),
    d = e("Interstitial"),
    u = e("Video"),
    p = e("Icon"),
    h = e("Custom"),
    f = e("AdUtils"),
    _ = e("BoxBannerAd"),
    y = cc._decorator,
    m = y.ccclass,
    g =
        (y.property,
        (function (e) {
            function t() {
                var t = e.call(this) || this;
                return (
                    (t._config = null),
                    (t._vivoNativeDateList = []),
                    (t._hideCallback = null),
                    (t._showCallback = null),
                    (t._nativeAdInitTime = 0),
                    (t._adCreating = !1),
                    (t._utils = f.default.instance),
                    (t._banner = new l.default()),
                    (t._interstitial = new d.default()),
                    (t._video = new u.default()),
                    (t._icon = new p.default()),
                    (t._custom = new h.default()),
                    (t._boxPortalAd = new _.default()),
                    t
                );
            }
            var o;
            return (
                __extends(t, e),
                (o = t),
                Object.defineProperty(t, "Instance", {
                    get: function () {
                        return null == o._instance && (o._instance = new o()), o._instance;
                    },
                    enumerable: !1,
                    configurable: !0
                }),
                (t.prototype.getBanner = function () {
                    return this._banner;
                }),
                (t.prototype.getConfig = function () {
                    return this._config;
                }),
                (t.prototype.onListenHome = function () {
                    var e = this,
                        t = !1;
                    cc.game.on(cc.game.EVENT_SHOW, function () {
                        t && (e._utils.log("切换前台"), (t = !1), e._showCallback && e._showCallback());
                    }),
                        cc.game.on(cc.game.EVENT_HIDE, function () {
                            t ||
                                (e._utils.log("切换后台"),
                                (t = !0),
                                e._hideCallback &&
                                    (e._hideCallback(),
                                    s.default.Instance.hideBanner(),
                                    s.default.Instance.hideInterstitial()));
                        });
                }),
                (t.prototype.initConfig = function (e, t) {
                    var o = this;
                    (this._config = e),
                        this._utils.log("config:------   " + JSON.stringify(e)),
                        this._config &&
                            (this._banner.init(e),
                            this._interstitial.init(e),
                            this._video.init(e),
                            this._icon.init(e),
                            this._custom.init(e),
                            this._boxPortalAd.init(e),
                            t && t(),
                            this._config.native_ad_enbable > 0 &&
                                (this.creatorNativeData(null),
                                this.schedule(function () {
                                    o.creatorNativeData(null);
                                }, 15)));
                }),
                (t.prototype.onHide = function (e) {
                    this._hideCallback = e;
                }),
                (t.prototype.onShow = function (e) {
                    this._showCallback = e;
                }),
                (t.prototype.getNetType = function (e) {
                    qg.getNetworkType({
                        success: function (t) {
                            e && e(t.type);
                        }
                    });
                }),
                (t.prototype.init = function () {}),
                (t.prototype.creatorNativeData = function (e) {
                    var t = this,
                        o = this;
                    if (o._adCreating) this._utils.log("----有广告未完成创建  ");
                    else if ((this._utils.log("--------load ad----------"), this._vivoNativeDateList.length >= 2))
                        this._utils.log("----广告未消耗，广告列表： " + this._vivoNativeDateList.length);
                    else {
                        var n = (new Date().getTime() - this._nativeAdInitTime) / 1e3;
                        this._utils.log("--------load ad time : " + n);
                        var i = function () {
                            o._adCreating = !0;
                            var n = new r.default();
                            n.initAd(o._config, function (i) {
                                (o._adCreating = !1),
                                    i &&
                                        ((o._nativeAdInitTime = new Date().getTime()),
                                        o._vivoNativeDateList.push(n),
                                        t._utils.log("--------广告缓存成功，列表： " + t._vivoNativeDateList.length)),
                                    e && e(i);
                            });
                        };
                        if (n < 3.1) {
                            var a = 3.1 - n;
                            return (
                                this._utils.log("--------离上次未到3秒，等待剩余时间 : " + n),
                                void this.scheduleOnce(i, a)
                            );
                        }
                        i();
                    }
                }),
                (t.prototype.hasNativeData = function () {
                    return (
                        this._vivoNativeDateList.length > 0 &&
                        (this._utils.log("----列表已存在广告： " + this._vivoNativeDateList.length), !0)
                    );
                }),
                (t.prototype.getVivoNativeData = function () {
                    this._utils.log("----广告列表： " + this._vivoNativeDateList.length);
                    var e = null;
                    return (
                        this._vivoNativeDateList.length > 0 && (e = this._vivoNativeDateList.shift()),
                        e && e.isReady()
                            ? (this._utils.log("-----存在新广告，用新的--------"), e)
                            : (this._utils.log("-----不存在广告或只存在旧广告--------"),
                              this._utils.log("-----广告列表还有： " + this._vivoNativeDateList.length),
                              null)
                    );
                }),
                (t.prototype.showBanner = function (e, t, o, n, i, a) {
                    if (
                        (void 0 === e && (e = l.BannerType.BOTTOM_CENTER),
                        void 0 === t && (t = null),
                        void 0 === o && (o = !1),
                        void 0 === n && (n = 0),
                        void 0 === i && (i = 0),
                        void 0 === a && (a = null),
                        this._banner)
                    ) {
                        if (null != this._config && 1 != this._config.native_ad_enbale)
                            return void this._banner.showBanner(e, c.NativeType.BANNER_NO_NATIVE, o, n, i, a);
                        this._banner.showBanner(e, t, o, n, i, a);
                    }
                }),
                (t.prototype.hideBanner = function () {
                    this._banner && this._banner.hideBanner();
                }),
                (t.prototype.hideIcon = function () {
                    this._icon && this._icon.hideIcon();
                }),
                (t.prototype.showInterstitial = function (e) {
                    if ((void 0 === e && (e = d.InterstitialType.INTERSTITIAL_GAME_OVER), null != this._config)) {
                        if (1 != this._config.native_ad_enbable) {
                            if (1 != this._config.custom_ad_ebable) return;
                            return void this._custom.customShow(e);
                        }
                        this._interstitial && this._interstitial.showInterstitial(e);
                    }
                }),
                (t.prototype.showIconAd = function (e, t, o) {
                    void 0 === e && (e = 0), this._icon && this._icon.showIconAd(e, t, o);
                }),
                (t.prototype.hideInterstitial = function () {
                    this._custom && this._custom.customHide();
                }),
                (t.prototype.vibrateShort = function () {
                    this._utils.log("---------vibrateShort-----"), qg.vibrateLong();
                }),
                (t.prototype.showRewardVideo = function (e, t, o) {
                    this._utils.log("---------showRewardVideo-----");
                    var n = this;
                    this._video &&
                        this._video.showRewardVideo(
                            function () {
                                e && e();
                            },
                            function () {
                                t && t();
                            },
                            function () {
                                o ? o() : n.showToast("暂无广告！");
                            }
                        );
                }),
                (t.prototype.showBoxBanner = function () {
                    this._boxPortalAd.initBoxBannerAd();
                }),
                (t.prototype.showboxPortalAd = function (e) {
                    this._boxPortalAd.initBoxPortalAd(e);
                }),
                (t.prototype.hideBoxBanner = function () {
                    this._boxPortalAd && this._boxPortalAd.closeBoxBanner();
                }),
                (t.prototype.hideBoxPortalAd = function () {
                    this._boxPortalAd && this._boxPortalAd.closeBoxPortalAd();
                }),
                (t.prototype.getClipboardData = function (e) {
                    var t = this;
                    qg.getClipboardData({
                        success: function (o) {
                            e && e(o.text), t._utils.log("Clipboar handling success: " + o.text);
                        },
                        fail: function (e, o) {
                            t._utils.log("handling fail, code = " + o);
                        }
                    });
                }),
                (t.prototype.getSystemInfoSync = function () {
                    return qg.getSystemInfoSync();
                }),
                (t.prototype.getUserId = function () {
                    var e = qg.getUserIdSync();
                    return e && e.userId ? e.userId : "vivo not user id";
                }),
                (t.prototype.getSource = function () {
                    return qg.getLaunchOptionsSync();
                }),
                (t.prototype.showToast = function (e) {
                    qg.showToast({message: e});
                }),
                (t._instance = null),
                (o = __decorate([m], t))
            );
        })(cc.Component));
o.default = g;
